<template>
  <div class="app-container">
    <el-form v-show="showSearch" ref="queryForm" :inline="true" :model="queryParams" label-width="68px" size="small">
      <el-form-item label="真实姓名" prop="RealName">
        <el-input
          v-model="queryParams.RealName"
          clearable
          placeholder="请输入真实姓名"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="看诊状态" prop="VisitState">
        <el-select v-model="queryParams.VisitState"
                   clearable placeholder="请选择看诊状态">
          <el-option
            v-for="dict in dict.type.regiser_state"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button icon="el-icon-search" size="mini" type="primary" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="RegisterList">
      <el-table-column align="center" label="id" prop="Register.Id"/>
      <el-table-column align="center" label="真实姓名" prop="Register.RealName"/>
      <el-table-column align="center" label="身份证号" prop="Register.IDnumber"/>
      <el-table-column align="center"
                       label="病历号码" prop="Register.CaseNumber"/>
      <el-table-column align="center" label="看诊日期" prop="VisitDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.Register.VisitDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="挂号科室" prop="DeptId"/>
      <el-table-column align="center" label="挂号医生" prop="UserId"/>
      <el-table-column align="center" label="看诊状态" prop="Register.VisitState">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.regiser_state" :value="scope.row.Register.VisitState"/>
        </template>
      </el-table-column>
      <el-table-column align="center" label="挂号级别" prop="RegistLevelId"/>
      <el-table-column align="center" class-name="small-padding fixed-width" label="操作">
        <template slot-scope="scope">
          <el-button
            v-hasPermi="['system:Register:remove']"
            icon="el-icon-s-order"
            size="mini"
            type="text"
            @click="handleCheck(scope.row)"
          >问诊
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :limit.sync="queryParams.size"
      :page.sync="queryParams.current"
      :total="total"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {listRegister, updateRegister} from "@/api/system/Register";

export default {
  name: "RegisterList",
  dicts: ['regiser_state', 'noon'],
  data() {
    return {
      loading: true,
      showSearch: true,
      total: 0,
      RegisterList: [],
      queryParams: {
        current: 1,
        size: 10,
        RealName: null,
        CaseNumber: null,
        VisitState: null,
      },
    }
  },
  created() {
    this.getList();
  },
  methods: {
    getList() {
      this.loading = true;
      listRegister(this.queryParams).then(response => {
        this.RegisterList = response.records;
        this.total = response.total;
        this.loading = false;
      });
    },
    handleQuery() {
      this.queryParams.current = 1;
      this.getList();
    },
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleCheck(row) {
      this.$confirm(`确定问诊病人${row.Register.RealName}吗?`)
        .then(() => {
          row.Register.VisitState = 2;
          updateRegister(row.Register).then(() => {
            this.$router.push({
              path: '/medicalRecord/info',
              query: {
                RegisterId: row.Register.Id,
                CaseNumber: row.Register.CaseNumber
              }
            })
          })
        })
    }
  }
};
</script>
